//
//  ConfirmWalletController.m
//  FbeeAPP
//
//  Created by dev-m on 2018/3/14.
//  Copyright © 2018年 mohao. All rights reserved.
//

#import "ConfirmWalletController.h"
#import "UIButton+BCYImage.h"
#import "FbeeCommitBtn.h"

@interface ConfirmWalletController ()
{
    
    NSString *walletAddr;
    
    UIScrollView *mainView;
    UIButton *closeBtn;
    UILabel *infoL;
    UILabel *walletL;
    FbeeCommitBtn *commit;
}

@end

@implementation ConfirmWalletController

-(void)dealloc
{
    NSLog(@"ConfirmWalletController dealloc");
}

-(instancetype)initWithAddr:(NSString *)addr
{
    self = [super init];
    
    if (self) {
        walletAddr = addr;
    }
    
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self buildView];
}

-(void)buildView
{
    
    mainView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, IPHONEWIDTH, IPHONEHEIGHT)];
    mainView.backgroundColor = UIColorFromRGBA(0x000000, 0.5);
    [self.view addSubview:mainView];
    

    infoL = [UILabel makeLabel:^(TTLabelExtend *make) {
        make.addTextColor(COLOR_WHITE).addFont([UIFont systemFontOfSize:14.0f]);
        make.addText(NSLocalizedString(@"textWalletAddrConfirmInfo", nil));
        make.setFrame(CGRectMake(17, self.largeTitle.bottom, IPHONEWIDTH - 17*2, 20));
        [self.view addSubview:make];
    }];
    
    walletL = [UILabel makeLabel:^(TTLabelExtend *make) {
        make.addText(walletAddr).addFont([UIFont systemFontOfSize:14.0f]).addTextColor(COLOR_WHITE);
        make.addTextAlignment(NSTextAlignmentCenter);
        make.numberOfLines = 3;
        make.setFrame(CGRectMake(30, self.largeTitle.bottom + 80, IPHONEWIDTH - 30*2, 40));
        [mainView addSubview:make];
    }];
    [mainView addSubview:walletL];
    
    commit = [[FbeeCommitBtn alloc] initWithTitle:NSLocalizedString(@"mConfirm", nil)];
    commit.centerX = IPHONEWIDTH/2;
    commit.top = walletL.bottom + 65;
    @weakify(self)
    [commit onClick:^{
        @strongify(self)
        [self saveWalletAddr];
    }];
    [mainView addSubview:commit];
    
    [self.largeTitle setTitle:NSLocalizedString(@"tNavUCenterWalletConfirm", nil)];
    [self.largeTitle setTitleColor:COLOR_WHITE];
    UIButton *back = [self.largeTitle viewWithTag:666];
    [back setImage:[UIImage imageNamed:@"nav_back_w"] forState:UIControlStateNormal];
    
    [self bringTitleToFront];
}

#pragma mark - request
-(void)saveWalletAddr
{
    [self post:WalletAdd_URL param:@{@"uid":[UserInfoManager sharedManager].userId,@"address":walletAddr} code:WalletAdd_URL_Code];
}

#pragma mark - response

-(void)requestSuccess:(id)data code:(NSInteger)code
{
    [UserInfoManager sharedManager].walletAddr = walletAddr;
    
    NSString *info = SafeGetStringValue([data objectForKey:@"msg"]);
    [NoticePopHelper showNoticeText:info];
    
    [[NSNotificationCenter defaultCenter] postNotificationName:Notification_AddWalletClose object:nil];
}

-(void)requestLogicError:(id)data code:(NSInteger)code
{
    [super requestSuccess:data code:code];
}

-(void)requestFailure:(NSError *)error code:(NSInteger)code
{
    
}



@end
